package com.yloveg.impl;
import java.util.ArrayList;

/** 
 * @Class: WebSocketMessageService
 * @Description:  使用webscoket连接向用户发送信息
 * @author JFPZ
 * @date 2017年5月15日 上午20:17:01
 */
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yloveg.controller.Websocket;
import com.yloveg.service.WSMessageService;
 
@Service("webSocketMessageService")
public class WSMessageServiceImpl implements WSMessageService  {
    private Logger logger = LoggerFactory.getLogger(WSMessageServiceImpl.class);
    //声明websocket连接类
    private Websocket websocket = new Websocket();
 
    /**
     * @Title: sendToAllTerminal
     * @Description: 调用websocket类给用户下的所有终端发送消息
     * @param @param userId 用户id
     * @param @param message 消息
     * @param @return 发送成功返回true，否则返回false
     */
    public Boolean sengToUser(Long fuserId,Long tuserId,String message){   
        logger.info("{}向用户{}发送的消息：{}",fuserId,tuserId,message);
        if(websocket.sendMessageToUser(fuserId,tuserId,message)){
            return true;
        }else{
            return false;
        }   
    }

	@Override
	public ArrayList<Long> getOnlineUser(Long userId) {
		return websocket.getOnlineUser(userId);
	}
    
}
